home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 January - Disc 2 / Macworld (1999-01) (Disk 2).dmg / Serious Demos / Symbolic Composer 4.2 / Environment / Projects / Questions & Answers / Q&A Programming Music / Programming robot compiler < prev    next >
Encoding:
Text File  |  1998-10-26  |  7.5 KB  |  240 lines  |  [TEXT/ScoM]

  1. PROGRAMMING ROBOT COMPILER
  2.  
  3. ;; ROBOT COMPILER
  4. ;; This lets SCOM compile in the background while working with
  5. ;; other applications. You can determine the number of songs you want,
  6. ;; and if you like some of the random pieces you can restore it by
  7. ;; using its random name. Any score can be robotized but you need to
  8. ;; understand the basics, which are explained here.
  9.  
  10. ;; Place the robot score in its own folder before you run it. The midi
  11. ;; files are saved in this directory. You can change this behaviour
  12. ;; customizing make-song-name. When compilation has finished select
  13. ;; the midi files in finder and double-click to open them in SCOM for
  14. ;; playing.
  15.  
  16. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  17. ;; extensions needed by the robot compiler
  18.  
  19. ; this enables to save a midi file to a directory path supplied
  20.  
  21. (defmacro play-file-f (songname &rest ll)
  22.   `(eval (append '(play-file-nocheck) (list ,songname) ',ll)))
  23.   
  24. ; this makes a song name based on the file name of the window (and its path)
  25. ; it returns a directory path string
  26. ;
  27. ; (make-song-name)
  28. ; --> Programming:Symbolic Composer 4.0:Master 0.1:Song 0.1
  29.  
  30. (defun make-song-name ()
  31.   (let* ((directory (mac-directory-namestring 
  32.                      (window-filename 
  33.                       (get-current-compile-window))))
  34.          (folder-name nil))
  35.     (str-cat directory 
  36.              "Master " (princ-to-string *robot-master-seed*) 
  37.              ":Song " (princ-to-string *robot-song-seed*))))
  38.  
  39. ; this runs the robot score
  40. ; each time the score is run, it uses a new random seed
  41. ; the song is saved on a file determined by the random seed value
  42. ; all songs are saved on directory determined by the master random seed
  43.  
  44. (defun run-robot-score (seed nbr-of-songs)
  45.   ; set seed to global *robot-master-seed* so that make-song-name can find it
  46.   (setq *robot-master-seed* seed)
  47.   ; make as many random seeds as there are songs
  48.   (setq random-seeds (generate-n-random-seeds seed nbr-of-songs))
  49.   ; run the score nbr-of-songs times
  50.   (dotimes (i nbr-of-songs)
  51.     ; get first random seed in the list and store it to a global 
  52.     ; so that make-song-name can find it
  53.     (setq *robot-song-seed* (pop random-seeds))
  54.     ; initialize random seed
  55.     (init-rnd *robot-song-seed*)
  56.     ; and run the score
  57.     (eval `(progn ,@score-program))))
  58.  
  59. ; customize run-robot-score when you need more parameters to
  60. ; control score behaviour, setq parameters to globals
  61.  
  62. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  63.  
  64.  
  65. #| boom-says-the-bass box
  66.  
  67. Before making a robot that creates 100 new pieces in an hour you
  68. need to understand the basics. Here is a simple groove box score.
  69. Run the score and keep changing the init-rnd seed. Each time you 
  70. get a new combination based on element definitions.
  71.  
  72. Some notes:
  73.  
  74. With current symbols snare perc and hihat might not be in your setup
  75. what the names say. define drummap or use def-drumset.
  76.  
  77. What you put in that will come out.
  78. Change element definitions. Replace them with generators.
  79. What does the timesheet do? Double-click def-section-timesheet. 
  80. When you understand how this score is put together you can add as much
  81. instruments as you want. Extend the timesheet.
  82.  
  83. Try randomizing the timesheet and rhythms with pulse-string. See
  84. the docs and you'll immediately see the possibilities. Use mix-strings
  85. to combine multiple pulse-string outputs.
  86.  
  87. Bass is fixed. Try changing it.
  88. If you work on dancable styles keep patterns 1, 2 and max 4 bars.
  89. Implement intelligent variation mechanisms.
  90.  
  91. If you are working on zones you are already on the level that you 
  92. can handle randomization on your own.
  93.  
  94. If you make enhancements to this example it is highly appreciated that
  95. you post it back to the list.
  96.  
  97. |#
  98.  
  99. ;;;;;; to make a score robot-runnable setq it to a variable in a 
  100. ;;;;;; quoted list, see below
  101. ;
  102. ; don't use init-rnd since it is set up outside
  103. ; include (null-compiler) to make each compile fresh
  104. ; otherwise the score can be any SCOM and Lisp, if you want to
  105. ; control more of its behaviour set up global variables in run-robot-score
  106. ; and test the variables inside the score, this way you can make the
  107. ; score use THIS tonality or THAT depending on the variable, or
  108. ; do other enhancements.
  109.  
  110. (setq score-program '(
  111.  
  112. (null-compiler)
  113.  
  114. (def-orchestra 'orchestra
  115.    all-instruments (drums instruments)
  116.    instruments (bass sequence)
  117.    drums (kick snare hihat perc)
  118. )
  119.  
  120. ; element definitions
  121.  
  122. (setq kicks '(
  123. ;    1---!---!---!---2---!---!---!---3---!---!---!---4---!---!---!---
  124.     "-   -   -   -   -   -   -   -   "
  125.     "-   -   -   - - -   -   -   -   "
  126.     "-   -   -   -   -   -   -   -   -   -   -   -   -   -   -   - - "
  127.     "-   -   -   -   -   -   -    ---"
  128. ))
  129.  
  130. (setq snares '(
  131. ;    1---!---!---!---2---!---!---!---3---!---!---!---4---!---!---!---
  132.     "    -       -       -       -       -       -       -       -   "
  133.     "  -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   - "
  134.     "    -       -       -       -       -       -       -      --   "
  135.     "          -               -               -               -     "
  136. ))
  137.  
  138. (setq hihats '(
  139. ;   1---!---!---!---2---!---!---!---3---!---!---!---4---!---!---!---
  140.    "------- - -- ------------ -- ---"
  141.    "---- ------- ------- -------- - "
  142.    "  -    -  -   -   -   -   -   - "
  143.    " - - - - - - - - - - - - - - -  "
  144.    "----------------"
  145. ))
  146.  
  147. (setq velocities '(
  148.    (90 100 110 120)
  149.    (120 100 110 100)
  150.    (100 120 80 110)
  151.    (127 90)
  152.    (120 100 80)
  153. ))
  154.  
  155. (setq symbols '(
  156.    (a b a c)
  157.    (a b c -b)
  158.    (a d c b)
  159.    (a a -b a)
  160.    (a b -b a)
  161. ))
  162.  
  163. (setq rhythms '(
  164. ;   1---!---!---!---2---!---!---!---3---!---!---!---4---!---!---!---
  165.    "- - --- -       "
  166.    "  --  -   -   - "
  167.    "  -  -  -  -----"
  168.    "  -- --         "
  169. ))
  170.  
  171.  
  172. (def-section-timesheet sect-a
  173.    ;
  174.    ; timesheet = bars that the instruments play
  175.    ;
  176.    with 1/1
  177.    tonality drums
  178.    ;           1       9       17      etc bars
  179.    ;           !---!---!---!---!---!---!---!---!
  180.    kick       "--------------- ------- --  "
  181.    hihat      "  --------------------- --  "
  182.    perc       "    ----------------------  "
  183.    snare      "      ----------------- --  "
  184.    ;
  185.    ; instruments
  186.    ;
  187.    tonality (activate-tonality (hirajoshi c 3))
  188.    ;           1       9       17      etc bars
  189.    ;           !---!---!---!---!---!---!---!---!
  190.    bass "        ------------"
  191.    sequence   "            ----------------"
  192.    ;
  193.    ; drums
  194.    ;
  195.    beat 1/16 ; !---!---!---!---!
  196.    kick       (pick-random kicks) '(b) with '(127)
  197.    snare      (pick-random snares) (list (pick-random '(c d e f))) with (pick-random velocities)
  198.    perc       (pick-random hihats) (list (pick-random '(p q r s t))) with (pick-random velocities)
  199.    hihat      (pick-random hihats) (list (pick-random '(j k l m n))) with (pick-random velocities)
  200.    ;
  201.    ; instruments
  202.    ;
  203.    beat 1/16 ; !---!---!---!---!
  204.    legato (fix 1/32)
  205.    sequence    (pick-random rhythms) (pick-random symbols) with (pick-random velocities)
  206.  
  207. )
  208.  
  209. (def-section sect-a
  210.    drums
  211.       channel 10
  212.    bass
  213.       channel 2
  214.       symbol '(a)
  215.       length '(-1/8 1/8)
  216.       velocity '(127)
  217.    sequence
  218.       channel 1
  219. )
  220.  
  221. (midiport :printer)
  222.  
  223. (def-tempo 140)
  224.  
  225. (play-file-f (make-song-name)
  226.    all-instruments '(sect-a)
  227. )
  228.  
  229. ))  ; end of setq
  230.  
  231. ; you can now run the score, supply master seed and number of songs
  232.  
  233. (run-robot-score 0.123 10)
  234.  
  235. ; You'll now have a subfolder Master 0.123 in the score root folder.
  236. ; This folder contains number of songs like Song 0.938362263811738.
  237. ; The number is a seed, when you want to restore the score you can
  238. ; supply the number manually to init-rnd. This feature is handy if
  239. ; you like a score and want to work more on that.
  240.